//
//  admanager.m
//  admanager
//
//  Created by chit on 4/3/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "oc_admanager.h"
#import "c_admanager.h"






@implementation OC_Admanager


- (void)adWhirlWillPresentFullScreenModal 
{
    
    WillPresentFullScreenModal();
}

- (void)adWhirlDidDismissFullScreenModal 
{
    DidDismissFullScreenModal();
    
}

- (void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlVieww 
{
    //1
    //[adWhirlView rotateToOrientation:UIInterfaceOrientationLandscapeRight];
	//2    
    [self adjustAdSize];
    
}


- (NSString *)adWhirlApplicationKey 
{
    return m_Key;
}

- (UIViewController *)viewControllerForPresentingModalView 
{
    return m_ViewController;    
}



- (void) AdInit:(UIViewController *)Root BannerKey:(NSString *)BannerKey FullScreenAdAppID:(NSString *)FullScreenAdAppID FullScreenAdKey:(NSString *)FullScreenAdKey
{
    
    m_Key = BannerKey;
    m_ViewController = Root;
    
    /*
    m_AdWhirlView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
       //4
    [ m_AdWhirlView updateAdWhirlConfig];
    
 
    //8
	m_AdWhirlView.clipsToBounds = YES;
    //9
    [m_ViewController.view addSubview:m_AdWhirlView];
    //10
    [m_ViewController.view bringSubviewToFront:m_AdWhirlView];
    //11
     */
      
    Chartboost *cb = [Chartboost sharedChartboost];
    cb.appId = FullScreenAdAppID;
    cb.appSignature = FullScreenAdKey;
    cb.delegate = self;
    [cb startSession];
    [cb cacheInterstitial];
        
}

- (void)didDismissInterstitial:(NSString *)location
{
    [[Chartboost sharedChartboost] cacheInterstitial:location];
    DidDismissFullScreenModal();
}

- (void) RequestFullScreenAd
{
    Chartboost *cb = [Chartboost sharedChartboost];
    
    if([cb hasCachedInterstitial])
    {
    // Show an interstitial
        [cb showInterstitial];
        WillPresentFullScreenModal();
    }
    else
        [cb cacheInterstitial];

}

- (void)adjustAdSize 
{
    /*
    [UIView beginAnimations:@"AdResize" context:nil];
    [UIView setAnimationDuration:0.7];
    CGSize adSize = [m_AdWhirlView actualAdSize];
    CGRect newFrame = m_AdWhirlView.frame;
    newFrame.size.height = adSize.height;
    newFrame.size.width = adSize.width;
    newFrame.origin.x = (m_ViewController.view.bounds.size.width - adSize.width)/2;
    newFrame.origin.y = m_ViewController.view.bounds.size.height - adSize.height;
    m_AdWhirlView.frame = newFrame;
    [UIView commitAnimations];
     */
}

- (UIColor *)adWhirlAdBackgroundColor 
{
    return [UIColor purpleColor];
}

- (UIColor *)adWhirlTextColor 
{
    return [UIColor cyanColor];
}

- (BOOL)adWhirlTestMode 
{
    return YES;
}

- (void) ShutDownAd
{
    /*
    if (m_AdWhirlView) 
    {
        [m_AdWhirlView removeFromSuperview];
        [m_AdWhirlView replaceBannerViewWith:nil];
        [m_AdWhirlView ignoreNewAdRequests];
        [m_AdWhirlView setDelegate:nil];
        m_AdWhirlView = nil;
    }
     */
    
    Chartboost *cb = [Chartboost sharedChartboost];
    [cb release];
}

- (void) Hide
{
    /*
    if (m_AdWhirlView) 
    {
        [m_AdWhirlView removeFromSuperview];
        [m_AdWhirlView ignoreNewAdRequests];
    }
     */
    
}

- (void) Show
{
    /*
    if(m_AdWhirlView)
    {
        [m_ViewController.view addSubview:m_AdWhirlView];        
        [m_ViewController.view bringSubviewToFront:m_AdWhirlView];        
        [m_AdWhirlView doNotIgnoreNewAdRequests];
           
    }
     */

}


@end
